const baseURL = "https://qqyifeng.cn:9001";

const request = (opts) => {
	uni.showLoading({
		title: "正在努力加载中~"
	});

	let httpDefaultOpts = {
		url: baseURL + opts.url,
		data: opts.data,
		method: opts.method,
		header: opts.method == 'GET' ? {
			'X-Requested-With': 'XMLHttpRequest',
			"Accept": "application/json",
			"Content-Type": "application/json; charset=UTF-8"
		} : {
			'X-Requested-With': 'XMLHttpRequest',
			'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
		},
		dataType: 'json',
	};

	let promise = new Promise((resolve, reject) => {
		uni.request(httpDefaultOpts).then(res => {
			// console.log(res)
			if (res[1].statusCode && res[1].statusCode == '200') {
				resolve(res[1].data)
			} else {
				resolve(res[1])
			}
			uni.hideLoading();
		}).catch(response => {
			reject(response)
			uni.hideLoading()
		});
	});
	
	return promise;
};
module.exports = {
	request
};
